package com.moleq.models;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import android.R.integer;

import com.moleq.enums.ItemType;
import com.moleq.logic.TransactionManager;
import com.moleq.service.ServiceManager;

public class SaleListItem implements Serializable {

	public long getEntryNum() {
		return entryNum;
	}

	public void setEntryNum(long entryNum) {
		this.entryNum = entryNum;
	}

	public String getUpc() {
		return upc;
	}

	public void setUpc(String upc) {
		this.upc = upc;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}
	
	public String getShowDescription() {
		String restult = "" ;
		if (!mDispalyContent.equals(description)  && GlobalInfo.getInstance().isShowDesc) {
			restult = description;
			if (restult.length() > 12 ) {
				restult = restult.substring(0, 12);
			}
		}
		return restult;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getUnitPrice() {
		return unitPrice;
		
	}

	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

	public int getQty() {
		return qty;
	}

	public void setQty(int qty) {
		this.qty = qty;
		vdrCouponBarcode = new String[qty];
	}

	public double getPrice() {
		
		double result = price;
		if (isRefund()) {
			result = -1 * price;
		}
		return result;
	}

	public void setPrice(double price) {
		double result = price;
		if (getIscoupon()) {
			result = result * -1;
		}
		this.price = result;
	}

	public boolean getIsWeight() {
		return isWeight;
	}

	public void setIsWeight(boolean isWeight) {
		this.isWeight = isWeight;
	}

	public double getWeight() {
		return weight;
	}

	public void setWeight(double weight) {
		this.weight = getBaseweight() - getTareWeight();
//		this.weight = weight;
	}
	public void setPoslineWeight(double weight) {
		this.weight = weight;
//		this.weight = weight;
	}
	
	public boolean isTaxable() {
		if (getTax1() || getTax2() || getTax3() || getTax4() || getTax5() || getTax6()){
			return true;
		}
		return false;
	}

	public void setTaxable(boolean taxable) {
		this.taxable = taxable;
	}

	public double getTaxRate() {
		return taxRate;
	}

	public void setTaxRate(double taxRate) {
		this.taxRate = taxRate;
	}

	public double getTax() {
		return tax;
	}

	public void setTax(double tax) {
		this.tax = tax;
	}

	public boolean getTax1() {
		return tax1;
	}

	public void setTax1(boolean tax1) {
		this.tax1 = tax1;
	}

	public boolean getTax2() {
		return tax2;
	}

	public void setTax2(boolean tax2) {
		this.tax2 = tax2;
	}

	public boolean getTax3() {
		return tax3;
	}

	public void setTax3(boolean tax3) {
		this.tax3 = tax3;
	}

	public boolean getTax4() {
		return tax4;
	}

	public void setTax4(boolean tax4) {
		this.tax4 = tax4;
	}

	public boolean getTax5() {
		return tax5;
	}

	public void setTax5(boolean tax5) {
		this.tax5 = tax5;
	}

	public boolean getTax6() {
		return tax6;
	}

	public void setTax6(boolean tax6) {
		this.tax6 = tax6;
	}

	public boolean getFollowdep() {
		return followdep;
	}

	public void setFollowdep(boolean followdep) {
		this.followdep = followdep;
	}

	public void setisWeight(boolean isWeight) {
		this.isWeight = isWeight;
	}

	public double getDep() {
		return dep;
	}

	public void setDep(double dep) {
		this.dep = dep;
	}

	public boolean getFoodstamp() {
		return foodstamp;
	}

	public void setFoodstamp(boolean foodstamp) {
		this.foodstamp = foodstamp;
	}

	public int getBottleDeposit() {
		return mBottleDeposit;
	}

	public void setBottleDeposit(int deposit) {
		this.mBottleDeposit = deposit;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	private long entryNum;
	private String upc;
	private String name;
	private String description = "";
	private double unitPrice;
	private int qty;
	private double price;
	private boolean isWeight;
	private double weight;
	private double baseweight = 0;
	private double tareWeight =0;
	private boolean taxable;
	private double taxRate;
	private double tax;
	public boolean tax1,ExemptTax1;
	public boolean tax2,ExemptTax2;
	public boolean tax3,ExemptTax3;
	public boolean tax4,ExemptTax4;
	public boolean tax5,ExemptTax5;
	public boolean tax6,ExemptTax6;
	private boolean followdep;
	private double dep = 0;
	private boolean foodstamp;
	private String parentId;
	private String id;
	private boolean isHaveBottle;
	private int mBottleDeposit; // F158;
	private int dep_group; // F263
	private ItemType itemType = ItemType.REGULAR;
	private PriceSetting mPriceSetting;
	private BottleSetting mBottleSeting; 
	private String mPriceDescription = "";
	private boolean isPkgItem = false;
//	private String pkgitemno;
	private String mMixMatchNum = "none";
	private String mMixMatchDesc = "";
	private String mWeightDesc = "";
	private String mTareDesc = "";
	private int tareCount;
	private List<TareSetting> mTareSettings;
	private boolean havepolinetare;
	private boolean havepolinediscnt;
	private boolean havepolinecoupon;
	private int age;
	private long poslineno;
	private String mDispalyContent = "";
	private boolean nodiscount;
	private int poslinediscntno;
	private boolean mIsRefund = false;
	private int ld_id = -1;
	private int lc_id = -1;
	private String insertType = "1000";
	private String poslineType = "A";
	//private String mTaxDesc = "";
	private Boolean iscoupon = false;
	private double couponvalue ;
	private double ItemDisntvalue ;
	private int mdepartment = -1;
	private String mDepDescription = "";
	private boolean wic;
	private boolean cvv;
	private double foodstampPrice;
	private double taxablePrice = price;
	private boolean serviceItem;
	private String[] vdrCouponBarcode;
	private int printer_id;
	private String mEachDescription = "";
	private String vdr_code;
	private String fam_code;
	private String vdr_coupon_code_no;
	private boolean isVdrCoupon;
	private List<String> linkVdrCouponItem;
	private boolean isMultCoupon = false;
	private int priceQty = 0;
	private int vdrQty = 0;
	private double vdrCouponPrice = 0;
	
	
	public double getVdrCouponPrice() {
		return vdrCouponPrice;
	}

	public void setVdrCouponPrice(double vdrCouponPrice) {
		this.vdrCouponPrice = vdrCouponPrice;
	}

	public int getUseQty(){
		
		int useQty = qty - priceQty - vdrQty;
		
		return useQty;
	}
	
	public int getPriceQty() {
		return priceQty;
	}

	public void setPriceQty(int priceQty) {
		this.priceQty = priceQty;
	}

	public int getVdrQty() {
		return vdrQty;
	}

	public void setVdrQty(int vdrQty) {
		this.vdrQty = vdrQty;
	}

	
	
	public boolean isServiceItem() {
		return serviceItem;
	}

	public void setServiceItem(boolean serviceItem) {
		this.serviceItem = serviceItem;
	}
	
	public int getPrinter_id() {
		return printer_id;
	}

	public void setPrinter_id(int printer_id) {
		this.printer_id = printer_id;
	}

	public double getBaseweight() {
		return baseweight;
	}

	public void setBaseweight(double baseweight) {
		this.baseweight = baseweight;
	}
	
	public double getFoodstampPrice() {
		return foodstampPrice;
	}

	public void setFoodstampPrice(double foodstampPrice) {
		this.foodstampPrice = foodstampPrice;
	}

	public double getTaxablePrice() {
		return taxablePrice;
	}

	public void setTaxablePrice(double taxablePrice) {
		this.taxablePrice = taxablePrice;
	}
	public boolean isWic() {
		return wic;
	}

	public void setWic(boolean wic) {
		this.wic = wic;
	}

	public boolean isCvv() {
		return cvv;
	}

	public void setCvv(boolean cvv) {
		this.cvv = cvv;
	}


	public String getDepDescription() {
		return mDepDescription;
	}

	public void setDepDescription(String mDepDescription) {
		this.mDepDescription = mDepDescription;
	}

	public int getMdepartment() {
		return mdepartment;
	}

	public void setMdepartment(int mdepartment) {
		this.mdepartment = mdepartment;
	}

	public boolean getIsExemptTax(int num){
		boolean lb_check = false;
		if( TransactionManager.getInstance().mTaxExempat == num || TransactionManager.getInstance().mTaxExempat == 0){
			lb_check = true;
		}
		
		return lb_check;
	}
	public void getExemptTaxnum(int num) {
		TransactionManager mTransmgr = TransactionManager.getInstance();
		int isexmpt = mTransmgr.mTaxExempat;
		if (num >= 0) {
			switch (num) {
			case 0:
				if (isexmpt == -1) {
					mTransmgr.exemptTax1able =0;
					mTransmgr.exemptTax2able =0;
					mTransmgr.exemptTax3able =0;
					mTransmgr.exemptTax4able =0;
					mTransmgr.exemptTax5able =0;
					mTransmgr.exemptTax6able =0;
					
					if (ExemptTax1){
						ExemptTax1 = false;
						setTax1(true);
					}
					if (ExemptTax2){
						ExemptTax2 =false;
						setTax2(true);
					}
					if (ExemptTax3){
						ExemptTax3 =false;
						setTax3(true);
					}
					if (ExemptTax4){
						ExemptTax4 =false;
						setTax4(true);
					}
					if (ExemptTax5){
						ExemptTax5 =false;
						setTax5(true);
					}
					if (ExemptTax6){
						ExemptTax6 =false;
						setTax6(true);
					}
					
					//exemptTaxnum = -1;
				}else{
					if(tax1){
						mTransmgr.exemptTax1able += getPrice();
						ExemptTax1 = true;
						setTax1(false);
					}
					if(tax2){
						mTransmgr.exemptTax2able += getPrice();
						ExemptTax2 = true;
						setTax2(false);
					}
					if(tax3){
						mTransmgr.exemptTax3able += getPrice();
						ExemptTax3 = true;
						setTax3(false);
					}
					if(tax4){
						mTransmgr.exemptTax4able += getPrice();
						ExemptTax4 = true;
						setTax4(false);
					}
					if(tax5){
						mTransmgr.exemptTax5able += getPrice();
						ExemptTax5 = true;
						setTax5(false);
					}
					if(tax6){
						mTransmgr.exemptTax6able += getPrice();	
						ExemptTax6 = true;
						setTax6(false);
					}
					//exemptTaxnum = 0;
				}
					
				break;
			case 1:
				if(tax1){
					//exemptTaxnum =1;
					ExemptTax1 = true;
					mTransmgr.exemptTax1able += getPrice();
					setTax1(false);
				}else if(ExemptTax1 == true){
					setTax1(true);
					ExemptTax1 = false;
					mTransmgr.exemptTax1able = 0;
					
					//exemptTaxnum = -1;
				}
				
				break;
			case 2:
				if(tax2){
					//exemptTaxnum =2;
					ExemptTax2 = true;
					setTax2(false);
					mTransmgr.exemptTax2able += getPrice();
				}else if(ExemptTax2 == true ){
					setTax2(true);
					ExemptTax2 = false;
					mTransmgr.exemptTax2able = 0;
					
					//exemptTaxnum = -1;
				}
				break;
			case 3:
				if(tax3){
					//exemptTaxnum =3;
					ExemptTax3 = true;
					setTax3(false);
					mTransmgr.exemptTax3able += getPrice();
				}else if(ExemptTax3 == true){
					setTax3(true);
					ExemptTax3 = false;
					mTransmgr.exemptTax3able= 0;
				
					//exemptTaxnum = -1;
				}
				break;
			case 4:
				if(tax4){
					//exemptTaxnum =4;
					ExemptTax4 = true;
					setTax4(false);
					mTransmgr.exemptTax4able += getPrice();
				}else if(ExemptTax4 == true){
					setTax4(true);
					ExemptTax4 = false;
					mTransmgr.exemptTax4able = 0;
					
					//exemptTaxnum = -1;
				}
				break;
			case 5:
				if(tax5){
					//exemptTaxnum =5;
					ExemptTax5 = true;
					setTax5(false);
					mTransmgr.exemptTax5able += getPrice();
				}else if(ExemptTax5 == true){
					setTax5(true);
					ExemptTax5 = false;
					mTransmgr.exemptTax5able = 0;
					
					//exemptTaxnum = -1;
				}
				break;
			case 6:
				if(tax6){
					//exemptTaxnum =6;
					ExemptTax6 = true;
					setTax6(false);
					mTransmgr.exemptTax6able += getPrice();
				}else if(ExemptTax6 == true){
					setTax6(true);
					ExemptTax6 = false;
					mTransmgr.exemptTax6able = 0;
				
					//exemptTaxnum = -1;
				}
				break;
				
			default:
				break;
			}
		}
		//return exemptTaxnum;
	}

	public double getItemDisntvalue() {
		return ItemDisntvalue;
	}

	public void setItemDisntvalue(double itemDisntvalue) {
		ItemDisntvalue = itemDisntvalue;
	}

	private String coupontype ;
	
	public String getCoupontype() {
		return coupontype;
	}

	public void setCoupontype(String coupontype) {
		this.coupontype = coupontype;
	}

	public boolean getHavepolinecoupon() {
		return havepolinecoupon;
	}

	public void setHavepolinecoupon(boolean havepolinecoupon) {
		this.havepolinecoupon = havepolinecoupon;
	}
	public double getCouponvalue() {
		return couponvalue;
	}

	public void setCouponvalue(double couponvalue) {
		this.couponvalue = couponvalue;
	}

	public Boolean getIscoupon() {
		return iscoupon;
	}

	public void setIscoupon(Boolean iscoupon) {
		this.iscoupon = iscoupon;
	}

	public String getmTaxDesc() {
		String result = "";
		if (getTax1() || getTax2() || getTax3() || getTax4() || getTax5() || getTax6()) result+="T";
//		if (getTax2()) result+="T2";
//		if (getTax3()) result+="T3";
//		if (getTax4()) result+="T4";
//		if (getTax5()) result+="T5";
//		if (getTax6()) result+="T6";
		if (getFoodstamp()) result+="F";
		if(!result.equals("")) result = " ("+result+")";
		return result;
	}

//	public void setmTaxDesc(String mTaxDesc) {
//		
//		this.mTaxDesc = mTaxDesc;
//	}
	public int getLc_id() {
		return lc_id;
	}

	public void setLc_id(int lc_id) {
		this.lc_id = lc_id;
	}

	public String getPoslineType() {
		String result = poslineType;
		if(iscoupon){
			result = "Q";
		}
		if (isRefund()) {
			result = "R";
		}
		return result;
	}

	public void setPoslineType(String poslineType) {
		if (isRefund()) {
			poslineType = "R";
		}
		this.poslineType = poslineType;
	}
	
	public String getInsertType() {
		return insertType;
	}

	public void setInsertType(String insertType) {
		this.insertType = insertType;
	}

	public int getLd_id() {
		return ld_id;
	}

	public void setLd_id(int ld_id) {
		this.ld_id = ld_id;
	}

	public boolean getHavepolinediscnt() {
		return havepolinediscnt;
	}

	public void setHavepolinediscnt(boolean havepolinediscnt) {
		this.havepolinediscnt = havepolinediscnt;
	}

	public int getPoslinediscntno() {
		return poslinediscntno;
	}

	public void setPoslinediscntno(int poslinediscntno) {
		this.poslinediscntno = poslinediscntno;
	}

	public String getmTareDesc() {
		return mTareDesc;
	}

	public void setmTareDesc(String mTareDesc) {
		this.mTareDesc = mTareDesc;
	}

	public boolean getNodiscount() {
		return nodiscount;
	}

	public void setNodiscount(boolean nodiscount) {
		this.nodiscount = nodiscount;
	}

	public long getPoslineno() {
		return poslineno;
	}

	public void setPoslineno(long poslineno) {
		this.poslineno = poslineno;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public boolean getHavepolinetare() {
		return havepolinetare;
	}

	public void setHavepolinetare(boolean havepolinetare) {
		this.havepolinetare = havepolinetare;
	}

	public List<TareSetting> getmTareSetting() {
		return mTareSettings;
	}

	public void setmTareSetting(List<TareSetting> mTareSetting) {
		this.mTareSettings = mTareSetting;
	}

	// =============code by feng 2012-07-13===========
	public BottleSetting getmBottleSeting() {
		return mBottleSeting;
	}

	public void setmBottleSeting(BottleSetting mBottleSeting) {
		this.mBottleSeting = mBottleSeting;
	}

	public int getTareCount() {
		return tareCount;
	}

	public void setTareCount(int count) {
		this.tareCount = count;
	}

//	public String getPkgitemno() {
//		return pkgitemno;
//	}

//	public void setPkgitemno(String pkgitemno) {
//		this.pkgitemno = pkgitemno;
//	}

	public boolean getPkgItem() {
		return isPkgItem;
	}

	public void setPkgItem(boolean isPkgItem) {
		this.isPkgItem = isPkgItem;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public ItemType getItemType() {
		return itemType;
	}

	public void setItemType(ItemType itemType) {
		this.itemType = itemType;
	}

	public static final String ROOT = "root";

	public void setHaveBottle(boolean isHaveBottle) {
		this.isHaveBottle = isHaveBottle;

	}

	public boolean getHaveBottle() {
		return isHaveBottle;
	}

	public void setPriceSetting(PriceSetting setting) {
		mPriceSetting = setting;

	}

	public PriceSetting getPriceSetting() {
		return mPriceSetting;
	}

	public void setPriceDescription(String desc) {
		mPriceDescription = desc;

	}

	public String getPriceDescription() {
		String result = mPriceDescription;
		if (!mPriceDescription.equals("")) {
			result = "  "+result;
		}
		return result;
	}

	public String getEachDescription() {
		String result = mEachDescription;
		if (!mEachDescription.equals("")) {
			result = "  "+result;
		}
		return result;
	}

	public void setEachDescription(String mEachDescription) {
		this.mEachDescription = mEachDescription;
	}

	public void setMixMatch(String mmNum) {
		mMixMatchNum = mmNum;

	}

	public String getMixMatch() {
		return mMixMatchNum;
	}

	public String getMixMatchDesc() {
		return mMixMatchDesc;
	}

	public void setMixMatchDesc(String mMixMatchDesc) {
		this.mMixMatchDesc = mMixMatchDesc;
	}

	public String getWeightDesc() {
		return mWeightDesc;
	}

	public void setWeightDesc(String mWeightDesc) {
		this.mWeightDesc = mWeightDesc;
	}

	public String getDisplayContent() {
		// TODO Auto-generated method stub
		String ls_tax_desc = "",result = mDispalyContent,refund_desc ="";
		
		ItemType it_type = getItemType();
		if (it_type == ItemType.REGULAR || it_type == ItemType.OPEN_DEPARTMENT || it_type == ItemType.ITEM_DISCOUNT_MANUAL
				|| it_type == ItemType.ENVIRONMENTAL_FEES || it_type == ItemType.ITEM_COUPON || it_type == ItemType.COUPON || it_type == ItemType.MULTIPLE_PRICE) {
			ls_tax_desc = getmTaxDesc();
		}
//		if (result != null && result.length() > 20) {
//			result = result.substring(0, 20);
//		}
		if (isRefund()) {
			refund_desc = " (Refund)";
		}
		return result+ " " + getShowDescription()+ getEachDescription() + getPriceDescription() + getmTareDesc() + ls_tax_desc + refund_desc;
	}
	
	public String getSenderContent(){
		String result = getDisplayContent();
		if (result.length() > 20) {
			result = result.substring(0, 20);
		}
		
		return result;
	}
	
	public void shiftTax(int shiftnum){	
		if (shiftnum >= 0) {
			switch (shiftnum) {
			case 0:
				boolean sTaxall = false;
				if (!getTax1() && !getTax2() && !getTax3() && !getTax4() && !getTax5() && !getTax6()){
					sTaxall = true;
				}
				setTax1(sTaxall);
				setTax2(sTaxall);
				setTax3(sTaxall);
				setTax4(sTaxall);
				setTax5(sTaxall);
				setTax6(sTaxall);
				break;
			case 1:
				setTax1(!tax1);
				break;
			case 2:
				setTax2(!tax2);
				break;
			case 3:
				setTax3(!tax3);
				break;
			case 4:
				setTax4(!tax4);
				break;
			case 5:
				setTax5(!tax5);
				break;
			case 6:
				setTax6(!tax6);
				break;
				
			default:
				break;
			}
		}
	}
	
	
	
	public void shiftFoodStamp(){
		setFoodstamp(!foodstamp);
	}

	public void setDisplayContent(String content) {
		// TODO Auto-generated method stub
		this.mDispalyContent = content;
	}

	public int getDep_group() {
		return dep_group;
	}

	public void setDep_group(int dep_group) {
		this.dep_group = dep_group;
	}

	public boolean isRefund() {
		return mIsRefund;
	}

	public void setRefund(boolean b) {
		this.mIsRefund = b;
	}

	public double getTareWeight() {
		return tareWeight;
	}

	public void setTareWeight(double tareWeight) {
		this.tareWeight = tareWeight;
	}
	
//	public void setVdrCouponBarcode(String value){
//		for (int i = 0; i < vdrCouponBarcode.length; i++) {
//			if(vdrCouponBarcode[i].equals(value)){
//				vdrCouponBarcode[i] = "";
//			}
//		}
//	}
	
	public int setVdrCouponBarcode(String value,int qty){
		for (int i = 0; i < vdrCouponBarcode.length; i++) {
			if(vdrCouponBarcode[i].equals(value)){
				if(qty > 0){
					vdrCouponBarcode[i] = "";
					qty--;
				}else{
					break;
				}
			}
		}
		return qty;
	}

	public String getVdr_code() {
		return vdr_code;
	}

	public void setVdr_code(String vdr_code) {
		this.vdr_code = vdr_code;
	}

	public String getFam_code() {
		return fam_code;
	}

	public void setFam_code(String fam_code) {
		this.fam_code = fam_code;
	}

	public String getVdr_coupon_code_no() {
		return vdr_coupon_code_no;
	}

	public void setVdr_coupon_code_no(String vdr_coupon_code_no) {
		this.vdr_coupon_code_no = vdr_coupon_code_no;
	}

	public boolean getIsVdrCoupon() {
		return isVdrCoupon;
	}

	public void setIsVdrCoupon(boolean isVdrCoupon) {
		this.isVdrCoupon = isVdrCoupon;
	}

	public List<String> getLinkVdrCouponItem() {
		return linkVdrCouponItem;
	}

	public void setLinkVdrCouponItem(List<String> linkVdrCouponItem) {
		this.linkVdrCouponItem = linkVdrCouponItem;
	}

	public String[] getVdrCouponBarcode() {
		return vdrCouponBarcode;
	}

	public void setVdrCouponBarcode(String[] vdrCouponBarcode) {
		this.vdrCouponBarcode = vdrCouponBarcode;
	}

	public boolean getIsMultCoupon() {
		return isMultCoupon;
	}

	public void setIsMultCoupon(boolean isMultCoupon) {
		this.isMultCoupon = isMultCoupon;
	}
	
	
//	public SaleListItem(){}
//	public SaleListItem(String upc,ItemType type,double dep,int group,String insertType){
//		this.upc = upc;
//		this.itemType = type;
//		this.dep = dep;
//		this.dep_group = group;
//		this.insertType = insertType;
//	}
}
